package com.github.gdxmap.core;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.backends.android.AndroidFragmentApplication;
import com.badlogic.gdx.input.GestureDetector;

/**
 * Created by free on 2016/12/6 0006.
 */
public class MapFragment extends AndroidFragmentApplication{
    public static String MAPOPTIONS="MAPOPTIONS";

    protected MapOptions mapOptions;

    protected GdxMap gdxMap;

    public MapFragment(){
        gdxMap=new GdxMap();
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        return initializeForView(gdxMap);
    }
    public void initialize(MapOptions mapOptions){
        this.mapOptions=mapOptions;

        if (gdxMap!=null){
            gdxMap.setMapOptions(mapOptions);
        }

        initEvents();
    }
    public void setGdxMapListener(GdxMapListener gdxMapListener) {
        if (gdxMap!=null) {
            this.gdxMap.setGdxMapListener(gdxMapListener);
        }
    }

    /**
     * 初始化触摸事件
     */
    private void initEvents(){
        Gdx.input.setInputProcessor(new GestureDetector(new MapInputProcessor(gdxMap)));
    }
}
